/*
 * @Date: 2025-06-13 10:50:10
 * @Auth: 463997479@qq.com
 * @LastEditors: 463997479@qq.com
 * @LastEditTime: 2025-08-04 10:53:41
 * @FilePath: \corpus\src\pages\Home\EditAngent\index.tsx
 */
import { Form, Input, Modal, Select } from 'antd';
import type React from 'react';
import { useEffect } from 'react';
import hooks from '../hooks/useHooks';
const EditAngent: React.FC = () => {
  const {
    ligentAgentData,
    setAngentVisible,

    detail,
    angentVisible,
    formAgent,
    editKnowledgeContent,
  } = hooks.useContainer();
  const title = '修改智能体';

  const handleSubmit = () => {
    formAgent.validateFields().then((vals) => {
      const nameArr = ligentAgentData
        .filter((item: any) => vals.intelligentId.indexOf(item.id) > -1 && item.label)
        .map((it: any) => it.label);
      const method = editKnowledgeContent;
      method.run({
        ...vals,
        intelligentName: nameArr,
      });
    });
  };

  useEffect(() => {
    if (angentVisible && detail) {
      formAgent.setFieldsValue({
        ...detail,
      });
    }
  }, [detail, angentVisible]);
  return (
    <Modal
      width={600}
      title={title}
      open={angentVisible}
      onCancel={() => {
        formAgent.resetFields();
        setAngentVisible(false);
      }}
      onOk={handleSubmit}
      confirmLoading={editKnowledgeContent.loading}
    >
      <Form labelCol={{ span: 4 }} form={formAgent}>
        <Form.Item name="id" hidden />

        <Form.Item label={'语料库名称'} name="name" rules={[{ required: true }]}>
          <Input disabled placeholder="请输入" />
        </Form.Item>
        <Form.Item
          label={'智能体'}
          name="intelligentId"
          rules={[{ required: true, message: '请选择' }]}
        >
          <Select
            style={{ width: '100% ' }}
            mode="multiple"
            placeholder="请选择"
            options={ligentAgentData}
          />
        </Form.Item>
      </Form>
    </Modal>
  );
};

export default EditAngent;
